﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace WoltersKluwer.SPChainGang.Core.ExtensionMethods
{
    public static class EnumerableExtensions
    {
        public static bool IsNullOrEmpty<T>(this T[] array)
        {
            return array == null || array.Length == 0;
        }

        public static bool IsNullOrEmpty(this ICollection collection)
        {
            return collection == null || collection.Count == 0;
        }

        public static bool IsNullPresent<T>(this T[] array) where T : class
        {
            return !array.IsNullOrEmpty() && array.Any(item => item == null);
        }

        public static bool IsIntersected<T>(this IList<T> list, ICollection collection)
        {
            if (IsNullOrEmpty(collection))
                return false;

            return list.Intersect(collection.Cast<T>()).Count() > 0;
        }
    }
}